using System;
using System.Xml;

namespace DNNContentBuilder.UserControls.FieldControls
{
	/// <summary>
	/// Summary description for DummyFormlet.
	/// </summary>
	public class DummyFormlet : BaseFieldControl, IFormlet
	{
		private readonly XmlDocument xmlDoc = new XmlDocument();
		private XmlNode xmlNode;

		private readonly Type   type;
		private object value;

		public DummyFormlet(object value, Type type)
		{
			this.type  = type;
			this.value = value;
		}

		#region IFormlet Members

		public bool IsValid
		{
			get
			{
				return false;
			}
		}

		public string GetValue(string XML)
		{
			xmlDoc.LoadXml(XML);

			xmlNode = xmlDoc.SelectSingleNode("//SystemType");
			xmlNode.InnerText = type.Name;

			xmlNode = xmlDoc.SelectSingleNode("//Value");

			xmlNode.InnerText = Convert.ToString(value);

			return xmlDoc.InnerXml;
		}

		public void SetValue(string XML)
		{
			xmlDoc.LoadXml(XML);
			xmlNode = xmlDoc.SelectSingleNode("//Value");

			value = xmlNode.InnerText;
		}

		public void SetConfig(string XML)
		{
			// TODO:  Add DummyFormlet.SetConfig implementation
		}

		#endregion
	}
}
